package util;

import org.apache.log4j.Logger;

public class Log {
	public static Logger log;

	private Log() {}
	
	/**@Desc
	 * @param type 1:debug,2:info,3:warn,4:error
	 * @param clazz
	 * @param msg
	 * @param e
	 */
	public static void  write(int type,Class clazz,String msg,Exception e){
		if(null==log){
			log= Logger.getRootLogger();
		}
		StringBuffer message=new StringBuffer();
		if(null!=clazz){
			message.append("class[");
			message.append(clazz.toString());
			message.append("]");
		}
		message.append(" 信息输出[");
		message.append(msg);
		message.append("]");
		
		
		switch (type) {
		case 1:
			log.debug(message.toString(), e);
			break;
		case 2:
			log.info(message.toString(), e);
			break;
		case 3:
			log.warn(message.toString(), e);
			break;
		case 4:
			log.error(message.toString(), e);
			break;
		default:
			log.info(message.toString(), e);
			break;
		}
	}
	public static void debug(String msg){
		 write(1,null,msg,null);
	}
	public static void info(String msg){
		 write(2,null,msg,null);
	}
	public static void warn(Class clazz,String msg,Exception ex){
		 write(3,clazz,msg,ex);
	}
}
